﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using ajayumi.develop.win32.Transport.WCF.Services;
using ajayumi.develop.win32.Transport.Utils;

namespace ajayumi.develop.win32.Transport.Client.WinForm
{
    /// <summary>
    /// 传输任务管理器
    /// </summary>
    internal class TransTaskManager
    {
        #region Properties

        static TransTaskManager m_Instance;
        public static TransTaskManager Instance
        {
            get { return m_Instance; }
        }

        /// <summary>
        /// 上传文件集合
        /// </summary>
        public TransFileCollection UploadFileCollection { get; private set; }
        /// <summary>
        /// 下载文件集合
        /// </summary>
        public TransFileCollection DownloadFileCollection { get; private set; }

        /// <summary>
        /// 任务备份文件路径
        /// </summary>
        public string TaskBakPath { get; set; }

        #endregion


        static TransTaskManager()
        {
            m_Instance = new TransTaskManager();
        }

        public TransTaskManager()
        {
            this.UploadFileCollection = new TransFileCollection();
            this.DownloadFileCollection = new TransFileCollection();

            this.TaskBakPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "tasks.xml");
        }

        public void Load()
        { }

        public void Save()
        {
            try
            {
                if (this.UploadFileCollection.Count > 0)
                {
                    SerializerHelper.SerializeXml<TransFileCollection>(this.UploadFileCollection, this.TaskBakPath);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }


    }
}
